import {$get, $post, $put} from '@js/request'
import { EAddressSchema } from '@src/components/schema/address'
import { FileSchema } from '@src/components/schema/fileSchema'
import { EServiceContent } from '@src/components/schema/service'

export async function getFileList (caseid: string): Promise<FileSchema[]> {
  const res = await $get(`/api/commission/document/${caseid}`, {
    page: 1,
    limit: 1000
  })
  return res.data.list
}

export async function getAddressListRequest (caseid: string): Promise<EAddressSchema[]> {
  const res = await $get('/api/commission/deliveraddress', {
    caseid,
    address_type: '电子地址'
  })
  return res.data
}

export async function getContentRequest (caseid: string, type: string, addressid: string): Promise<EServiceContent> {
  const res = await $get('/api/commission/deliver/getDigitalDeliverContent', {
    caseid,
    topic_type: type,
    addressid
  })
  return res.data
}

// 更新送达数据
export async function updateModalRequest (d: {[k: string]:any}) {
  const id = d.id
  delete d.id
  const res = await $put(`/api/commission/deliver/${id}`, d)
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}

// 新增送达数据
export async function addModalRequest (d: {[k: string]:any}) {
  const res = await $post('/api/commission/deliver', d)
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}
